from langchain.output_parsers import DatetimeOutputParser
from langchain_community.llms import Ollama
from langchain_core.prompts import PromptTemplate

llm = Ollama(model="llama3", base_url="http://localhost:11434")
# 定义提示模板
parser  = DatetimeOutputParser()
prompt = PromptTemplate(template="{question}\n{format_instructions}", input_variables=["question"],
                        partial_variables = {"format_instructions":parser.get_format_instructions()})

print(prompt)
chain = prompt | llm | parser
response = chain.invoke({"question":"中华人民共和国什么时候成立的?"})
print(response)



